<?php
/**
 * Galdic project
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Galdic
 * @package    Galdic
 * @copyright  Copyright (c) 2009 vifito (http://vifito.eu)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * Admin_Model_DbTable_Terms
 * 
 * @package    Galdic
 * @copyright  Copyright (c) 2009 vifito (http://vifito.eu)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: Terms.php 1 2009-09-12 11:32:58Z vifito $
 */
class Admin_Model_DbTable_Terms extends Zend_Db_Table
{
	protected $_name = "terms";
	protected $_id   = "id";
    protected $_dependentTables = array('Admin_Model_DbTable_Definitions');
    
    public function insert($data)
    {
        parent::insert($data);
        $db = $this->getAdapter();
                
        $id = $db->lastInsertId();
        
        return $id;
    }
    
    /**
     * Get options to include in html select form
     *
     * @see Zend_Form_Element_Multi::addMultiOptions()
     * @param int|null $excludeId Exclude element with this identifier
     * @return array Hash with options by TermId to use with select form
     */
    public function getHtmlOptions($excludeId=null)
    {        
        $hash = array();
        $terms = $this->fetchAll();
                
        if($terms) {
            foreach($terms as $term) {
                if($excludeId!=$term->id) {
                    $hash[$term->id] = $term->name;
                }
            }
        }
        
        return $hash;
    }    
}
